﻿using System.Threading;


namespace project1113.SpeechRecoginzer
{
    class timerTick
    {
        private int timeCounter;
        private Timer timer;
        private bool isRunning;
        private object lockObject = new object();

        public timerTick()
        {
            this.timeCounter = 0;
            this.isRunning = false;
        }

        public void ResetTimerCounter()
        {
            timeCounter = 0;
        }

        public int GetTimerCounter()
        {
            return timeCounter;
        }

        public void timerTickerStart(int intervalMilliseconds)
        {
            if (isRunning)
            {
                // Timer is already running
                return;
            }

            timer = new Timer(TimerCallback, null, 0, intervalMilliseconds);
            isRunning = true;
        }

        public void timerTickerStop()
        {
            lock (lockObject)
            {
                if (timer != null)
                {
                    timer.Dispose();
                    timer = null;
                    isRunning = false;
                }
            }
        }

        private void TimerCallback(object state)
        {
            lock (lockObject)
            {
                timeCounter++;
            }
        }
        

    }
}
